package org.tis.tools.senior.module.developer.entity.enums;


import org.tis.tools.model.enums.BaseEnum;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author lijunhua
 * @date 2018/9/4
 *
 */
public enum DeployWhere implements BaseEnum {

    BS_WORK_USER("bs.work.user"),
    TWS_WORK_USER("tws.work.user"),
    BS_LIB("bs.lib"),
    TWS_LIB("tws.lib"),
    TWS_PLUGINS("tws.plugins"),
    BS_DBV("bs.数据库"),
    BS_CPNFIG("bs.config"),
    GOVERNOR("governor");


    private final String value;

    DeployWhere(final String value) {
        this.value = value;
    }

    @Override
    public Serializable deserialze() {
        return value;
    }

    @Override
    public Serializable getValue() {
        return value;
    }

    @Override
    public String toString() {
        return value;
    }

    public static List<Map<String, Object>> getDeployWhere(PatchType patchType){
        List<Map<String, Object>> patchTypes = new ArrayList<>();
        for(DeployWhere deployWhere:DeployWhere.values()){
            Map<String, Object> map = new HashMap<>();
            switch (patchType){
                case CFG:
                    if(BS_DBV.equals(deployWhere) || BS_CPNFIG.equals(deployWhere) ||
                            BS_LIB.equals(deployWhere) || TWS_LIB.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                case JAR:
                    if(BS_LIB.equals(deployWhere) || BS_LIB.equals(deployWhere) ||
                            BS_LIB.equals(deployWhere) || TWS_LIB.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                case ECD:
                    if(TWS_WORK_USER.equals(deployWhere) || BS_WORK_USER.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                case EPD:
                    if(TWS_WORK_USER.equals(deployWhere) || BS_WORK_USER.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                case EXE_JAR:
                    if(TWS_LIB.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                case PLUGINS:
                    if(TWS_PLUGINS.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                case DBV:
                    if(BS_DBV.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                case WAR:
                    if(GOVERNOR.equals(deployWhere)){
                        map.put("name", deployWhere);
                        map.put("isLeaf", true);
                        patchTypes.add(map);
                    }
                    break;
                default:
                    patchTypes.add(null);
            }
        }
        return patchTypes;
    }
}
